package news.controller;

import news.service.IUpdateTopicService;
import news.service.UpdateTopicServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 19373
 * 更新数据
 */
@WebServlet("/updateTopic")
public class UpdateTopicController extends HttpServlet {
    private final IUpdateTopicService iUpdateTopicService = new UpdateTopicServiceImpl();
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置响应内容类型
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("utf-8");
        //1.接受参数
        //2.存储数据
        String newTopicName = request.getParameter("newTopicName");
        Integer topicId = Integer.parseInt(request.getParameter("topicId"));

        iUpdateTopicService.updateTopic(topicId, newTopicName);

        //3.返回成功响应

        request.getRequestDispatcher(request.getContextPath() + "/news/main/maintopic-query.jsp").forward(request, response);
    }

}

